package com.ruoyi.shop.oss.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.shop.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.annotation.MultipartConfig;


@RestController
@RequestMapping("/api/oss")
@CrossOrigin
@MultipartConfig(maxFileSize = 1024 * 1024 * 50) // 最多传50M
public class OssController extends BaseController {

    @Autowired
    private OssService ossService;

    @PostMapping("/upload")
    public String uploadOssFile(@RequestParam("file") MultipartFile file) throws Exception{
        //获取上传文件 MultipartFile
        //返回图片在oss上的路径
        String url = ossService.uploadFileAvatar(file);

        return url;
    }

}
